# This demostrates early cut off optimization from "Build Systems A la Carte"
# 1) Run `earthly +run`
# 2) Add or remove a comment to main.cpp
# 3) ReRun `earthly +run`
# Result: `build` will rerun, but `link` and `run` will be served from the cache as main.o is unchanged

VERSION 0.6
FROM alpine
WORKDIR /code
RUN apk add --update --no-cache build-base

build:
    COPY src .
    RUN gcc -c main.cpp
    SAVE ARTIFACT main.o

link:
    COPY +build/main.o .
    RUN gcc -o main main.o
    SAVE ARTIFACT main

run:
    COPY +link/main .
    RUN ./main
